local zhishenwu = fk.CreateSkill {
  name = "lingling__zhishenwu",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__zhishenwu"] = "治神武",
  [":lingling__zhishenwu"] = "锁定技，每当你使用或打出一张牌后，若你本局使用或打出牌的倍数达到某倍，你随机获得一张：<br>三倍，【杀】或【闪】；五倍，【桃】或【酒】；八倍，【无中生有】或【决斗】。",

  ["@lingling__zhishenwu"] = "治神武",
}

zhishenwu:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@" .. zhishenwu.name, 0)
end)

local zhishenwu_spec = {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(zhishenwu.name) and
        not table.every({ 3, 5, 8 }, function(num)
            return player:getMark("@" .. zhishenwu.name) % num ~= 0
        end)
    end,
    on_use = function(self, event, target, player, data)
        local loopList = table.filter({ 3, 5, 8 }, function(num)
        return player:getMark("@" .. zhishenwu.name) % num == 0
        end)

        local cards = {}
        for _, count in ipairs(loopList) do
        local cardList = "slash,jink"
        if count == 5 then
            cardList = "peach,analeptic"
        elseif count == 8 then
            cardList = "ex_nihilo,duel"
        end
        local randomCard = player.room:getCardsFromPileByRule(cardList)
        if #randomCard > 0 then
            table.insert(cards, randomCard[1])
        end
        end

        if #cards > 0 then
        player.room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, zhishenwu.name, nil, false, player)
        end
    end,
}
zhishenwu:addEffect(fk.CardUsing, zhishenwu_spec)
zhishenwu:addEffect(fk.CardResponding, zhishenwu_spec)

local zhishenwu_refresh_spec = {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhishenwu.name)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@" .. zhishenwu.name, 1)
  end,
}
zhishenwu:addEffect(fk.CardUsing, zhishenwu_refresh_spec)
zhishenwu:addEffect(fk.CardResponding, zhishenwu_refresh_spec)

return zhishenwu